<template>
  <div class="app-container">
    <TableFilter
      :data="filter"
      v-model="query"
      ref="filter"
      @change="changeFilter"
    ></TableFilter>
    <el-table
      v-loading="loading"
      border
      :data="tableData"
      style="width: 100%"
      :header-cell-style="{ background: '#f2f2f2' }"
    >
      <el-table-column prop="结算时间" label="结算时间" min-width="150">
      </el-table-column>
      <el-table-column prop="住院号" label="住院号"> </el-table-column>
      <el-table-column prop="姓名" label="姓名"> </el-table-column>
      <el-table-column prop="Drg编码" label="DRG编码"> </el-table-column>
      <el-table-column prop="Drg名称" label="DRG名称" min-width="300">
      </el-table-column>
      <el-table-column prop="主要诊断编码" label="主要诊断编码">
      </el-table-column>
      <el-table-column prop="主要诊断名称" min-width="200" label="主要诊断名称">
      </el-table-column>
      <el-table-column prop="手术编码" label="主要手术及操作编码">
      </el-table-column>
      <el-table-column prop="手术名称" label="主要手术及操作名称">
      </el-table-column>
      <el-table-column prop="住院总费用" label="住院总费用"> </el-table-column>
      <el-table-column prop="医保范围金额" label="医保范围金额">
      </el-table-column>
      <el-table-column prop="Drg权重" label="DRG权重"> </el-table-column>
      <el-table-column prop="Ddrg标准支付金额" label="DRG标准支付金额">
      </el-table-column>
      <el-table-column prop="基金支付比例" label="基金支付比例">
      </el-table-column>
      <el-table-column prop="项目结算基金支付" label="项目结算基金支付">
      </el-table-column>
      <el-table-column prop="医保基金drg支付" label="医保基金DRG支付">
      </el-table-column>
      <el-table-column prop="DRG盈亏状况" label="DRG盈亏状况">
        <template slot-scope="{ row }">
          <span
            :style="{ color: Number(row.DRG盈亏状况) < 0 ? 'red' : '#333' }"
            >{{ row.DRG盈亏状况 }}</span
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script lang="ts">
import TableFilter from "@/components/TableFilter";
import { Component, Vue } from "vue-property-decorator";
import { getrptrzmx } from "@/api/statistics";
import dayjs from "@/utils/dayjs.min.js";
import { dept2doc } from "@/api/patient";
@Component({
  name: "drgrzmx",
  components: {
    TableFilter,
  },
  computed: {
    filter() {
      return {
        date: {
          props: {
            options: [{ label: "结算时间", value: 0 }],
            isTwoRange: true,
            type: "daterange",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
          },
          keys: ["timeType", "kssj", "jssj"],
        },
        inline: [
          {
            props: {
              label: "科室",
              is: "el-select",
              filterable: true,
              options: this.deptList,
            },
            keys: "ksmc",
          },
        ],
      };
    },
  },
})
export default class extends Vue {
  private dataInfo: any = null;
  private deptList: any = [];
  private tableData: any = [];
  private loading: any = false;
  private query: any = {
    timeType: 0,
    kssj: "",
    jssj: "",
    ksmc: "",
    page: 1,
    size: 10,
  };

  private async created() {
    this.getData();
    this.getDepts();
  }
  public async getDepts() {
    // let curDate = new Date();
    // let t = `${this.Format("yyyyMMddh", curDate)}${parseInt(
    //   curDate.getMinutes() / 5 + ""
    // )}`;
    let d: any = await dept2doc({ t: dayjs().format("YYYYMMDD") });

    d = d.data || [];
    let deptts = Array.from(new Set(d.map((it: any) => it.科室)));
    this.deptList = [...deptts.map((it: any) => ({ label: it, value: it }))];
  }
  private async getData() {
    this.loading = true;
    const res = await getrptrzmx(this.query);
    this.tableData = res.data;
    this.loading = false;
  }
  private changeFilter(e) {
    let data = {
      ...e,
    };
    for (let key in data) {
      if (!data[key] && data[key] != 0) delete data[key];
    }
    this.query = data;
    this.getData();
  }
}
</script>

<style lang="scss" scoped></style>
